# Contributor: Eli Schwartz <eschwartz@archlinux.org>
# Contributor: Brendan MacDonell <macdonellba at gmail dot com>
# Contributor: Linmiao Xu <linmiao.xu@gmail.com>
# Contributor: Juan Miguel Cejuela <juanmi@jmcejuela.net>

pkgname=python-apsw
pkgver=3.40.0.0
pkgrel=2
pkgdesc="Python wrapper for SQLite"
arch=('loong64' 'x86_64')
url="https://github.com/rogerbinns/apsw"
license=('MIT')
makedepends=('python-setuptools')
depends=('python' 'sqlite')
source=("apsw-$pkgver.tar.gz::https://github.com/rogerbinns/apsw/archive/$pkgver.tar.gz")
sha512sums=('61ae7d0a6f394176af462c5e80eae1f8fdc9395fcb64d4956c755d552ab0dcac83349633e7867f2fa661a6b707c80b4ae65fd68cd91b0f0d2535aedf65b4a517')
b2sums=('9539bbffd9cbcdee58e798261f9fb09a3f691d442cc80de664ce3d48b6f36608624e8f0b718edf87171bd8e68999ee16ea3829698e9d3277afa5b33931f464cc')

build() {
  cd apsw-${pkgver}

  python setup.py build --enable=load_extension
}

check() {
  cd "$srcdir"/apsw-${pkgver}

  gcc ${CFLAGS} ${CPPFLAGS} ${LDFLAGS} -fPIC -shared -o testextension.sqlext src/testextension.c
  # do glob expansion in variable assignment
  local python_version=$(python -c 'import sys; print("".join(map(str, sys.version_info[:2])))')
  PYTHONPATH="$PWD/build/lib.linux-$CARCH-cpython-${python_version}" python -m unittest discover -vs .
}

package() {
  cd "$srcdir"/apsw-${pkgver}

  python setup.py install --root="$pkgdir" --optimize=1 --skip-build
  install -D -m644 LICENSE "$pkgdir"/usr/share/licenses/$pkgname/LICENSE
}
